package com.apps.ftapp.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.apps.ftapp.R;
import com.apps.ftapp.bean.Lesson;

import java.util.List;

/**
 * Created by lau on 2018/3/12.
 */

public class TimeTableAdapter extends ArrayAdapter<Lesson> {
    private int resource;
    private Context context;
    private List<Lesson> list;

    public TimeTableAdapter(Context context, int resource, List<Lesson> objects) {
        super(context, resource, objects);
        this.resource = resource;
        this.context = context;
        list = objects;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Lesson lesson = getItem(position);
        View view;
        ViewHolder viewHolder;
        if (convertView == null) {
            view = LayoutInflater.from(context).inflate(resource, parent, false);
            viewHolder = new ViewHolder();
            viewHolder.startTime = view.findViewById(R.id.start_time);
            viewHolder.title = view.findViewById(R.id.title);
            view.setTag(viewHolder);
        } else {
            view = convertView;
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.startTime.setText(lesson.getStartTime() + "-" + lesson.getEndTime());
        viewHolder.title.setText(lesson.getTitle());
        return view;
    }

    class ViewHolder {
        TextView startTime;
        TextView title;

    }
}
